import React, { ComponentType } from "react";
import { RouteProps } from "react-router-dom";
const { lazy } = React;
interface routeType extends RouteProps {
  name: string;
  path: string;
  components?: ComponentType;
  keep?: number;
}
function retry(
  fn: (...rest: any[]) => Promise<any>,
  retriesTimes = 5,
  interval = 1000
): Promise<any> {
  return new Promise((resolve, reject) => {
    fn()
      .then(resolve)
      .catch((error: any) => {
        setTimeout(() => {
          if (retriesTimes === 0) {
            reject(error);
            return;
          }
          retry(fn, retriesTimes - 1, interval).then(resolve, reject);
        });
      });
  });
}

export const routers: routeType[] = [
  {
    name: "登录",
    path: "/login",
    components: lazy(() => retry(() => import("@views/login"))),
  },
  {
    name: "小组管理",
    path: "/",
    components: lazy(() => retry(() => import("@views/group"))),
  },
  {
    name: "小组管理",
    path: "/group",
    components: lazy(() => retry(() => import("@views/group"))),
  },
  {
    name: "组员管理",
    path: "/team",
    components: lazy(() => retry(() => import("@views/team"))),
  },
  {
    name: "期数时间管理",
    path: "/issueTime",
    components: lazy(() => retry(() => import("@views/issueTime"))),
  },
  {
    name: "排行榜",
    path: "/ranking",
    components: lazy(() => retry(() => import("@views/ranking"))),
  },
];

const stepList:routeType[]= [
  { name: "探测计划书", path: "prospectus" },
  { name: "财务报表", path: "report" },
  // 系统方案设计
  { name: "探测计划报告", path: "planReport" },
  { name: "采购报表", path: "purchaseReport" },
  // 工程实现
  { name: "探测总结报告", path: "detectSummary" },
  // 系统测试
  { name: "测试报告评测", path: "testReport" },
  // 飞行任务设计
  { name: "发射任务设计报告", path: "designReport" },
  // 任务实施
  { name: "发射总结报告", path: "launchSummary" },
  // 商业运营
  { name: "商业计划书", path: "teamBusinessPlan" },
  { name: "证书颁发", path: "certificate" },
  { name: "拍卖结果", path: "auction" },
  { name: "盈利分析", path: "profit" },
];

export const routerStage: routeType[] = [
  // 制订科学目标
  {
    name: "知识讲解",
    path: "explain",
    components: lazy(() => retry(() => import("@views/publicPages/explain"))),
  },
  {
    name: "场外咨询预约",
    path: "appointment",
    components: lazy(() => retry(() => import("@views/publicPages/appointment"))),
  },
  // !下面的用一个页面即可
  ...stepList.map((item) => ({
    ...item,
    components: lazy(() => retry(() => import("@views/common/index"))),
  })),
];
